import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test1/api/Url.dart';
import 'package:flutter_test1/api/http/http_request.dart';
import 'package:flutter_test1/constant/Constant.dart';
import 'package:flutter_test1/preference/PreferencesManager.dart';
import 'package:flutter_test1/views/login/login.dart';
import 'package:flutter_test1/views/main/main.dart';

class Welcome extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _Welcome();
  }
}

class _Welcome extends State<Welcome>{

  @override
  void initState() {
    super.initState();
    initData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Image.asset("assets/images/ic_launcher.png"),
      ),
    );
  }

  void initData() async {
    await PreferencesManager.getInstance().init();
    SRHttpRequest.getInstance()
        .init(url: Url.serverURL, htmlUrl: Url.serverURL);
    Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) {
      if(PreferencesManager.getInstance().getBoolean(Constants.ISLOGIN)){
        return MainPage();
      }else{
        return LoginPage();
      }
    }));
  }
}